package com.wg.dome;

import cn.hutool.core.util.StrUtil;
import com.wg.core.net.OperationResponse;
import com.wg.net.rpc.Operation;

public class ErrorHelper {

    public static OperationResponse getInvalidResponse(Operation operation) {
        return getErrorResponse(operation.getRequest().getOperationCode(), ErrorCode.OPERATION_INVALID, operation.getErrorMessage());
    }

    public static OperationResponse getErrorResponse(short operationCode, ErrorCode errorCode, Object... args) {
        OperationResponse response = new OperationResponse(operationCode);
        response.setReturnCode(errorCode.getCode());
        response.setDebugMessage(StrUtil.format(errorCode.getMsg(), args));
        return response;
    }
}
